package com.qfmy.controller.assistant;

import com.qfmy.service.assistant.ChatService;
import com.qfmy.vo.assistant.AiAnswerVo;
import lombok.extern.slf4j.Slf4j;

import common.result.Result;
import jakarta.annotation.Resource;
import model.entity.assistant.AiAnswer;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.controller
 * @date 2025/5/18
 * @description 智能助手
 */
@Slf4j
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/chat")
public class ChatController {

    /**
     * 注入service
     */
    @Resource
    private ChatService chatService;

    /**
     * 语音播放
     */
    @RequestMapping("/audio")
    public Result audio(@RequestParam String audio){
        byte[] a = chatService.audio(audio);
        return Result.ok(a);
    }

    /**
     * 获取历史对话
     */
    @RequestMapping("/history")
    public Result history(){
        List<AiAnswer> history = chatService.history();
        return Result.ok(history);
    }

    /**
     * 根据时间进行删除
     */
    @RequestMapping("/deleteByTime")
    public Result<String> deleteByTime(@RequestParam  String time){
        chatService.deleteByTime(time);
        return Result.ok("删除成功");
    }

    /**
     * 根据时间获取历史记录
     */
    @RequestMapping("/getHistoryByTime")
    public Result<List<AiAnswerVo>> getHistoryByTime(@RequestParam String time){
        List<AiAnswerVo> historyByTime = chatService.getHistoryByTime(time);
        return Result.ok(historyByTime);
    }

    /**
     * 清除缓存
     */
    @RequestMapping("/clearCache")
    public Result clearCache(){
        chatService.clearCache();
        return Result.ok("清除缓存成功");
    }

    /**
     * 语音识别
     */
    @RequestMapping("/voice")
    public Result voice(@RequestParam String voice){
        String content = chatService.voice(voice);
        return Result.ok(content);
    }

    /**
     * 语音对话
     */
    @RequestMapping("/voiceStream")
    public Result voiceStream(@RequestParam String voice){
        String content = chatService.voiceStream(voice);
        return Result.ok(content);
    }

    /**
     * 调用阿里的tts获取语音
     */
    @RequestMapping("/tts")
    public Result tts(@RequestParam String text){
        String url = chatService.tts(text);
        return Result.ok(url);
    }



}
